﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CardCharger.lib;

namespace CardCharger.forms
{
    public partial class UserCardIssuerForm : Form
    {
        CardOS cos;
        UserCardIssue uci;
        IssueSetting issueSetting = new IssueSetting();

        public UserCardIssuerForm(CardOS _cos)
        {
            InitializeComponent();
            cos = _cos;

            //发卡类
            uci = new UserCardIssue(cos);
            uci.Issueloghandler += uci_loghandler;
        }

        void uci_loghandler(object sender, string msgType, string msgLog, string options)
        {
            if (this.richTextBox1.InvokeRequired)
            {

                Ulitily.LogEventHandler h = new Ulitily.LogEventHandler(uci_loghandler);
                this.richTextBox1.BeginInvoke(h, new object[] { 
                sender,msgType,msgLog,options});
            }
            else {

                this.richTextBox1.AppendText(msgType +":" + msgLog + "\r\n");
            
            }
        }

        private void button_Issue_Click(object sender, EventArgs e)
        {
            
            if (uci.cardos.icardReader.readerFd.ToInt32() > 0)
            {
                uci.Issue(issueSetting.Get());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.richTextBox1.Clear();
        }

        private void b_Setting_Click(object sender, EventArgs e)
        {
            issueSetting.Show();
        }

    }
}
